//
//  FSCHomeworkController.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/22.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit

var hw_id : Int = 0

class FSCHomeworkController: UITableViewController {

    var homeworkListVM = FSCHomeworkListViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.register(UINib.init(nibName: "FSCTableViewCell", bundle: nil), forCellReuseIdentifier: "homeworkCell")
        tableView.rowHeight = 110 * KWidth_ScaleW
        view.backgroundColor = UIColor.colorWithHex(hexColor: grayColor)
        
        downLoadData()
        
    }

    func downLoadData() -> Void {
        homeworkListVM.loadData { [weak self](isOk) in
            if isOk {
                self?.tableView.reloadData()
            }
        }
    }
    

}



// MARK: - Table view data source
extension FSCHomeworkController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return homeworkListVM.homeworkModelArr.count
}
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "homeworkCell", for: indexPath) as! FSCTableViewCell
        
        let model = homeworkListVM.homeworkModelArr[indexPath.row]
        cell.model = model
        
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath) as! FSCTableViewCell
        let vc = FSCManagerController()
        hw_id = (cell.model?.hw_id)!
        navigationController?.pushViewController(vc, animated: true)
    }

}
